//缓冲区输入控制LED
const int LedPin = 7;

void setup() {
  pinMode(LedPin, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  String BullString = "";
  while (Serial.available() > 0) {
    char text = Serial.read();
    BullString += text;

  }
  BullString = Trim(BullString);

  if (BullString == "off") {
    digitalWrite(LedPin, HIGH);
    BullString = "";
  }

  if (BullString == "no") {
    digitalWrite(LedPin, LOW);
    BullString = "";
  }
  delay(500);
}

String Trim(String str) {
  char arr[] = {'0', '0', '0', '0', '0'};
  str.toCharArray(arr , str.length());
  String text = "";
  for (int i = 0; i < 5 ; i++) {
    if (arr[i] != "" && arr[i] != '0') {
      text += (String)arr[i];
    }
  }
  return text;
}
